{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bobby\n"
     ]
    }
   ],
   "source": [
    "## __getattr__, __getattribute__\n",
    "## __getattr__ 就是在查找不到属性的时候调用\n",
    "\n",
    "from datetime import date\n",
    "\n",
    "class User:\n",
    "    def __init__(self, info={}):\n",
    "        self.info = info\n",
    "        \n",
    "    def __getattr__(self, item):\n",
    "#         return \"not find attr\"\n",
    "#         print(item)\n",
    "#         return self.info[item]\n",
    "        return 'imooc'\n",
    "\n",
    "    # 未找到属性处理方法的入口，如果\n",
    "    def __getattribute__(self, item):\n",
    "        return 'bobby'\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    user = User(info={'company_name': 'imooc', 'name': 'bobby'})\n",
    "    print(user.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
